﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArithmeticExpressionCalculator
{
    class CorrectValueInsert
    {
        string str;
        double value;
        public CorrectValueInsert(string str, double value)
        {
            this.str = str;
            this.value = value;
        }
        public string Exchange(int left_boundary, int right_boundary)
        {
            if (left_boundary != 0)
            {
                if (str[left_boundary - 1] == '-') 
                        value *= -1;
                if (str[left_boundary-1] == '-' || str[left_boundary-1] == '+')
                    left_boundary--;
            }
            string insert_part="+";
            string value_str = Convert.ToString(value);
            if (value < 0) insert_part = value_str;
            else insert_part = insert_part + value_str;

            string right_str = "";
            string left_str = "";
            char[] array_right = new char[str.Length - right_boundary - 1];
            char[] array_left = new char[left_boundary];
            if (right_boundary != str.Length - 1)
            {
                str.CopyTo(right_boundary + 1, array_right, 0, str.Length - right_boundary - 1);
                right_str = new string(array_right);
            }
            if (left_boundary != 0)
            {
                str.CopyTo(0, array_left, 0, left_boundary);
                left_str = new string(array_left);
            } 
            return left_str + insert_part + right_str;
        }
    }
}
